package com.bbx.demo.thrift;

import com.bbx.demo.thrift.impl.MessageServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TProcessorFactory;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.server.THsHaServer;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.TTransportException;

@Slf4j
public class ThriftServer {

    public static void main (String [] args) throws TTransportException {
        //socket 对象
        TNonblockingServerSocket serverSocket = new TNonblockingServerSocket(8095);
        THsHaServer.Args arg = new THsHaServer.Args(serverSocket).maxWorkerThreads(4).minWorkerThreads(2);
        MessageService.Processor<MessageServiceImpl> messageServiceProcessor = new MessageService.Processor<>(new MessageServiceImpl());

        //协议
        arg.protocolFactory(new TCompactProtocol.Factory());
        //传输
        arg.transportFactory(new TFramedTransport.Factory());
        //处理器
        arg.processorFactory(new TProcessorFactory(messageServiceProcessor));
        THsHaServer tHsHaServer = new THsHaServer(arg);
        log.info("[{}]......Start .....", tHsHaServer);
        tHsHaServer.serve();
    }
}
